Q1.
library(tidyverse)
## -- Attaching packages --------------------------------------------------------------------------------------------------------- tidyverse 1.2.1 --
## v ggplot2 2.2.1 v purrr 0.2.4
## v tibble 1.4.2 v dplyr 0.7.4
## v tidyr 0.8.0 v stringr 1.3.0
## v readr 1.1.1 v forcats 0.3.0
## -- Conflicts ------------------------------------------------------------------------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(readxl)
library(plyr)
## -------------------------------------------------------------------------
## You have loaded plyr after dplyr - this is likely to cause problems.
## If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
## library(plyr); library(dplyr)
## -------------------------------------------------------------------------
##
## Attaching package: 'plyr'
## The following objects are masked from 'package:dplyr':
##
## arrange, count, desc, failwith, id, mutate, rename, summarise,
## summarize
## The following object is masked from 'package:purrr':
##
## compact
passengers <- read_xls("data/WebAirport_FY_1986-2017.xls", sheet=3, skip=6)
tidy_data <- passengers %>%
select(AIRPORT, Year, INBOUND, OUTBOUND, INBOUND__1, OUTBOUND__1) %>%
rename(c("INBOUND" = "Domestic_inbound", "OUTBOUND" = "Domestic_outbound", "INBOUND__1" = "International_inbound", "OUTBOUND__1" = "International_outbound"))
tidier_data <- tidy_data %>%
gather(Domestic_inbound, Domestic_outbound, International_inbound, International_outbound, key = "typeofflight_bound", value = "count")
tidiest_data <- tidier_data %>%
separate("typeofflight_bound", c("type_of_flight", "bound")) %>%
drop_na(AIRPORT) %>% filter(AIRPORT != "TOTAL AUSTRALIA")
View(tidiest_data)
Q2. a.
ggplot(tidiest_data, aes(x = type_of_flight)) +
geom_bar(aes(weight=count)) +
facet_wrap(~Year, ncol = 8)
tidy_data_drop <- tidy_data %>%
drop_na(AIRPORT) %>%
filter(AIRPORT != "TOTAL AUSTRALIA")
library(ggplot2)
library(plotly)
##
## Attaching package: 'plotly'
## The following objects are masked from 'package:plyr':
##
## arrange, mutate, rename, summarise
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
plot_b <- ggplot(tidy_data_drop, aes(x = Domestic_inbound, y = Domestic_outbound)) +
geom_point(mapping = aes(colour = AIRPORT)) +
xlab("Domestic inbound") +
ylab("Domestic outbound") +
facet_wrap(~Year, nrow=4) +
theme(legend.position = "none")
ggplotly(plot_b)
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`
The airports with the most domestic flights are Sydney, Melbourne and Brisbane.
plot_c <- ggplot(tidy_data_drop, aes(x = International_inbound, y = International_outbound)) +
geom_point(mapping = aes(colour = AIRPORT)) +
xlab("International inbound") +
ylab("International outbound") +
facet_wrap(~Year, nrow=4) +
theme(legend.position = "none")
ggplotly(plot_c)
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`
Q3. From the bar graph, we can see that throughout all the years, the number of flights in total have increased significantly. From our first scatterplot, we can see that the number of domestic flights have been increasing for all airports, with Sydney airport leading in the number of domestic flights. For international flights, only a few number of airports have shown a significant increase of flights, mainly in Sydney, Melbourne and Brisbane. However, Sydney continues to lead in the number of international flights. The plots for domestic flights show roughly equal numbers of inbound and outbound passengers at the airports. International flights, particularly in recent years tend to have more inbound passengers than outbound passengers, which is consistent with Australia’s positive rate of immigration.